package com.finance.system.bean.pojo;


import com.finance.framework.lang.BaseObject;
import lombok.Data;
import org.apache.commons.lang.StringUtils;


@Data
public class RegionDetail extends BaseObject{

		private String name;//区域名称
		private String code;//区域编码
		private int level;//级别 （0为国家 1为省直辖市 2为地级市 3县）
		private String provinceCode;
		private String provinceName;
		private String cityCode;
		private String cityName;

		public String getProvinceCode(){
			return StringUtils.isNotBlank(this.provinceCode) ? this.provinceCode : this.level ==1? this.code : "";
		}
		public String getCityCode(){
			return StringUtils.isNotBlank(this.cityCode) ? this.cityCode : this.level ==2? this.code : "";
		}
		public String getProvinceName(){
			return StringUtils.isNotBlank(this.provinceName) ? this.provinceName : this.level ==1? this.name : "";
		}
		public String getCityName(){
			return StringUtils.isNotBlank(this.cityName) ? this.cityName : this.level ==2? this.name : "";
		}

		@Override
		public boolean equals(Object object){
			if(object instanceof RegionDetail){
				RegionDetail regionCode = (RegionDetail) object;
				return regionCode.getId().equals(this.getId());
			}
			return false;
		}
		@Override
		public int hashCode(){
			return this.getId().hashCode();
		}

		@Override
        public String toString(){
			String str = "";
			switch (level){
				case 1:
					str = this.name;
					break;
				case 2:
					str = this.provinceName+"-"+this.name;
					break;
				case 3:
					str = this.provinceName +"-"+this.cityName +"-"+this.name;
					break;
				default:
						break;
			}
			return str;
		}
 }